#ifndef VIRTUALPAINTENGINE_H
#define VIRTUALPAINTENGINE_H

#include "virtualdevice_global.h"
#include <QWidget>
#include <QTimer>
#include <array>
#include "../qlui/paintengine.h"

#define SCREEN_WIDTH 50
#define SCREEN_HEIGHT 20

class VirtualPaintEngine;

class Screen : public QWidget
{
    Q_OBJECT
public:
    Screen(VirtualPaintEngine* engine);

private:
    VirtualPaintEngine* engine_;

protected:
    virtual void paintEvent(QPaintEvent *) override;
};

class VIRTUALDEVICESHARED_EXPORT VirtualPaintEngine: public QObject, public PaintEngine
{
    Q_OBJECT
public:
    VirtualPaintEngine();
    ~VirtualPaintEngine();

    virtual int writeText(QRect rect, const QString& text, Color fontColor, Color backColor) override;
    virtual int clearRect(QRect rect) override;
    virtual int clear() override;

protected slots:
    void paint();

private:
    Screen *window_;
    QTimer *timer_;
    std::array<std::array<QChar, SCREEN_WIDTH>, SCREEN_HEIGHT> frame_;
    std::array<std::array<QColor, SCREEN_WIDTH>, SCREEN_HEIGHT> font_color_;
    std::array<std::array<QColor, SCREEN_WIDTH>, SCREEN_HEIGHT> back_color_;

    friend class Screen;
};

#endif // VIRTUALPAINTENGINE_H
